﻿using System.Globalization;
using System.Windows.Data;

namespace CoreModule.Converters
{
    public class SocialCardMaskConverter : IValueConverter
    {
        /// <summary>
        /// 
        /// </summary>
        public string Mask { get; set; } = "*";
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return "-";
            }

             

            if (value is string)
            {
                var str = value as string;

                if (str.Length <= 4)
                {
                    return "****";
                }
                else
                {

                   var middle= string.Join("", Enumerable.Repeat(Mask, str.Length - 4));

                    return str.Substring(0,2)+ middle + str.Substring(str.Length-2,2);
                }

            }
            return "-";
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
